Ext.namespace("Nippy.Components.Dialogs");
Nippy.Components.Dialogs.EditImage = Ext.extend(Ext.Window, {
	constructor: function(config){
		Nippy.Components.Dialogs.EditImage.superclass.constructor.apply(this, arguments);
    }
	,initComponent: function(){
		this.image = new Ext.BoxComponent({
	        autoEl: {tag: 'img'}
		});
		this.grid = new Nippy.Components.Grids.ImageSizes();
		var s = this.grid.getSelectionModel();
		s.on('rowselect',this.imageSelected,this);
		Ext.apply(this, {
            title: "Редактирование изображения",
            //layout: 'fit',
            layout: 'border',
	        items: [
				{
					region: 'west',
					anchor: '30%',
					width: 300,
					split: true,
					autoScroll:true,
					items: this.image 
				},{
	        		region: 'center',
		        	anchor: '70%',
		        	layout: 'fit',
	        		items: this.grid
        	}]
        	,buttons: [{text: 'Выход', scope: this, handler: this.exitClick}]
		});
		
		Nippy.Components.Dialogs.EditImage.superclass.initComponent.apply(this, arguments);
	}
	,exitClick: function(){
		this.close();
	}
	,imageSelected: function(s,ri,r){
		var i = r.data;
		this.image.el.dom.src='/pics/gallery/'+i.Id+'_'+i.SizeId+'_'+i.Width+'x'+i.Height+'.'+i.Ext;
		this.image.el.dom.width=i.Width;
		this.image.el.dom.height=i.Height;
		this.image.el.dom.alt=i.Alt;
		this.image.el.dom.title=i.Title;
	}
	,show: function(id){
		this.grid.load(id);
    	Nippy.Components.Dialogs.EditImage.superclass.show.call(this,arguments);
    }
});